package lucid.hrms.management.language;

import org.apache.commons.lang.StringUtils;
import org.codehaus.grepo.query.commons.aop.QueryMethodParameterInfo;
import org.codehaus.grepo.query.hibernate.generator.CriteriaGenerator;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

public class LanguageCriteriaGenerator implements CriteriaGenerator {
	public DetachedCriteria generate(QueryMethodParameterInfo qmpi) {
		LanguageCriteria languageCriteria = qmpi.getParameterByParamName("languageCriteria", LanguageCriteria.class);
		DetachedCriteria criteria = DetachedCriteria.forClass(Language.class);

		String name = languageCriteria.getName();
		if (StringUtils.isNotEmpty(name)) {
			criteria.add(Restrictions.like("name", name + '%'));
		}

		return criteria;
	}
}